<?php

namespace common\models\db\tables;

use Yii;

/**
 * This is the model class for table "{{%docu_tag}}".
 *
 * @property string $docu_id
 * @property string $tag_id
 *
 * @property Tag $tag
 * @property Docu $docu
 */
class DocuTag extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%docu_tag}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['docu_id', 'tag_id'], 'required'],
            [['docu_id', 'tag_id'], 'integer'],
            [['docu_id', 'tag_id'], 'unique', 'targetAttribute' => ['docu_id', 'tag_id']],
            [['tag_id'], 'exist', 'skipOnError' => true, 'targetClass' => Tag::className(), 'targetAttribute' => ['tag_id' => 'id']],
            [['docu_id'], 'exist', 'skipOnError' => true, 'targetClass' => Docu::className(), 'targetAttribute' => ['docu_id' => 'id']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'docu_id' => Yii::t('app', 'Docu ID'),
            'tag_id' => Yii::t('app', 'Tag ID'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTag()
    {
        return $this->hasOne(Tag::className(), ['id' => 'tag_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getDocu()
    {
        return $this->hasOne(Docu::className(), ['id' => 'docu_id']);
    }
}
